package com.example.communitypro.controller;

import com.example.communitypro.pojo.Comment;
import com.example.communitypro.pojo.Notification;
import com.example.communitypro.service.*;
import com.example.communitypro.util.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;
    @Autowired
    private UserCollectionService userCollectionService;
    @Autowired
    private UserLikesService userLikesService;
    @Autowired
    private UserReportService userReportService;
    @Autowired
    private NotificationService notificationService;


    @ResponseBody
    @RequestMapping(value = "/addComment")
    @CrossOrigin
    public Result addComment(Comment record){
        Notification notification1 = new Notification();
        notification1.setNotificationDate(new Date());

        notification1.setNotificationType(5);
        notification1.setPostNo(record.getPostNo());
        notification1.setUserNo(record.getUserNo());
        notificationService.addNotification(notification1);

        return commentService.addComment(record);
    }

    @ResponseBody
    @RequestMapping(value = "/dropComment")
    @CrossOrigin
    public Result dropComment(Integer commentNo){
        return commentService.dropComment(commentNo);
    }

    @ResponseBody
    @RequestMapping(value = "/modifyComment")
    @CrossOrigin
    public Result modifyComment(Comment record){
        return commentService.modifyComment(record);
    }

    @ResponseBody
    @RequestMapping(value = "/queryComment")
    @CrossOrigin
    public Result queryComment(Integer commentNo){
        return commentService.queryComment(commentNo);
    }

    @ResponseBody
    @RequestMapping(value = "/queryUserComment")
    @CrossOrigin
    public Result queryUserComment(Integer user_no){
        return commentService.queryUserComment(user_no);
    }

    @ResponseBody
    @RequestMapping(value = "/queryUserPassComment")
    @CrossOrigin
    public Result queryUserPassComment(Integer user_no, Integer comment_status){
        return commentService.queryUserPassComment(user_no,comment_status);
    }

    @ResponseBody
    @RequestMapping(value = "/queryAllPassComment")
    @CrossOrigin
    public Result queryAllPassComment(Integer comment_status){
        return commentService.queryAllPassComment(comment_status);
    }

    @ResponseBody
    @RequestMapping(value = "/queryPostComment")
    @CrossOrigin
    public Result queryPostComment(Integer post_no, Integer user_no){
        return commentService.queryPostComment(post_no,user_no);
    }

    @ResponseBody
    @RequestMapping(value = "/queryHotComment")
    @CrossOrigin
    public Result queryHotComment(Integer post_no, Integer user_no){
        return commentService.queryHotComment(post_no,user_no);
    }

    @ResponseBody
    @RequestMapping(value = "/queryAllComment")
    @CrossOrigin
    public Result queryAllComment(){
        return commentService.queryAllComment();
    }

    @ResponseBody
    @RequestMapping(value = "/queryReply")
    @CrossOrigin
    public Result queryReply(Integer commentNo,Integer userNo){
        return commentService.queryReply(commentNo,userNo);
    }
    @ResponseBody
    @RequestMapping(value = "/queryReplyUser")
    @CrossOrigin
    public Result queryReplyUser(Integer replyNo){
        return commentService.queryReplyUser(replyNo);
    }

    @ResponseBody
    @RequestMapping(value = "/queryFather")
    @CrossOrigin
    public Result queryFather(Integer commentNo,Integer userNo){
        return commentService.queryFather(commentNo,userNo);
    }
}
